package coredb;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/** Entity class for Account 
 *
 * @author New
 */
@Entity
@Table(name = "account")
@NamedQueries({
    @NamedQuery(name = "Account.updateBalance", query = "UPDATE Account a SET a.balance = :balance WHERE a.accno = :accno"),
    @NamedQuery(name = "Account.findAll", query = "SELECT a FROM Account a"),
    @NamedQuery(name = "Account.findByBalance", query = "SELECT a FROM Account a WHERE a.balance = :balance"),
    @NamedQuery(name = "Account.findByAccno", query = "SELECT a FROM Account a WHERE a.accno = :accno")})
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @Column(name = "balance")
    private double balance;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "accno")
    private Integer accno;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "accno")
    private Collection<Transaction> transactionCollection;
    @JoinColumn(name = "userid", referencedColumnName = "userId")
    @ManyToOne(optional = false)
    private Customer userid;

    /**
     *
     */
    public Account() {
    }

    /**
     *
     * @param accno
     */
    public Account(Integer accno) {
        this.accno = accno;
    }

    /**
     *
     * @param accno
     * @param balance
     */
    public Account(Integer accno, double balance) {
        this.accno = accno;
        this.balance = balance;
    }

    /**
     *
     * @return
     */
    public double getBalance() {
        return balance;
    }

    /**
     *
     * @param balance
     */
    public void setBalance(double balance) {
        this.balance = balance;
    }

    /**
     *
     * @return
     */
    public Integer getAccno() {
        return accno;
    }

    /**
     *
     * @param accno
     */
    public void setAccno(Integer accno) {
        this.accno = accno;
    }

    /**
     *
     * @return
     */
    public Collection<Transaction> getTransactionCollection() {
        return transactionCollection;
    }

    /**
     *
     * @param transactionCollection
     */
    public void setTransactionCollection(Collection<Transaction> transactionCollection) {
        this.transactionCollection = transactionCollection;
    }

    /**
     *
     * @return
     */
    public Customer getUserid() {
        return userid;
    }

    /**
     *
     * @param userid
     */
    public void setUserid(Customer userid) {
        this.userid = userid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (accno != null ? accno.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Account)) {
            return false;
        }
        Account other = (Account) object;
        if ((this.accno == null && other.accno != null) || (this.accno != null && !this.accno.equals(other.accno))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "coredb.Account[ accno=" + accno + " ]";
    }
    
}
